package cc.telecomdigital.tdstock.Services;

import java.util.ArrayList;
import java.util.List;

//The point is to cover the non-used feature
public class LSStringList
{
	private List<String>	_listItem;

	public LSStringList()
	{
		_listItem = new ArrayList<String>();
	}

	public LSStringList(LSStringList iNewList)
	{
		_listItem = new ArrayList<String>();
		_listItem.addAll(iNewList._listItem);
	}

	public int GetSize()
	{
		return _listItem.size();
	}

	public void ReplaceList(LSStringList iNewList)
	{
		Clear();
		_listItem.addAll(iNewList._listItem);
	}

	public void ReplaceList(String[] iStringArray)
	{
		Clear();
		
		int count, index;
		
		count = iStringArray.length;
		for (index = 0; index < count; index++)
			_listItem.add(iStringArray[index]);
	}
	
	public boolean IsEmpty()
	{
		return _listItem.isEmpty();
	}

	public int IndexOf(String iItem)
	{
		return _listItem.indexOf(iItem);
	}

	public boolean Add(String iItem)
	{
		if (_listItem.contains(iItem))
			return false;

		return _listItem.add(iItem);
	}
	
	//Return to the current location, also work as re-arrange
	public int Add(int iLocation, String iItem)
	{
		if (_listItem.contains(iItem))
			_listItem.remove(iItem);

		_listItem.add(iLocation, iItem);
		return _listItem.indexOf(iItem);
	}

	public boolean Remove(String iItem)
	{
		if (_listItem.contains(iItem) == false)
			return false;

		return _listItem.remove(iItem);
	}

	public boolean RemoveAt(int iLocation)
	{
		if (iLocation >= _listItem.size())
			return false;

		_listItem.remove(iLocation);
		return true;
	}

	public String Get(int iLocation)
	{
		if (iLocation >= _listItem.size())
			return null;

		return _listItem.get(iLocation);
	}

	public boolean Contains(String iStringKey)
	{
		return _listItem.contains(iStringKey);		
	}
	
	//Looking at partial of
	public boolean ContainsAny(String iStringKey)
	{
		int orgSize, listCount, index;
		String tmpItem;
		
		listCount = _listItem.size();
		if (listCount == 0)
			return false;
		
		orgSize = iStringKey.length();
		for (index = 0; index < listCount; index++)
		{
			tmpItem = _listItem.get(index);
			if (tmpItem == null)
				continue;
			
			if (orgSize > tmpItem.length())
				continue;
			
			if (tmpItem.indexOf(iStringKey) != -1)
				return true;							
		}
		
		return false;
	}
	
	public void Clear()
	{
		_listItem.clear();
	}

	@Override
	public String toString()
	{
		int count, index;
		String bufferString;

		count = _listItem.size();
		if (count == 0)
			return null;

		bufferString = _listItem.get(0);
		for (index = 1; index < count; index++)
			bufferString += "," + _listItem.get(index);

		return bufferString;
	}

	public String[] toArray()
	{
		int count, index;
		String[] retValue;

		count = _listItem.size();
		if (count == 0)
			return null;

		retValue = new String[count];
		for (index = 0; index < count; index++)
			retValue[index] = _listItem.get(index);

		return retValue;
	}

}
